-
Notifications
You must be signed in to change notification settings - Fork 120
Added support for more test methods, including Yarn and Composer #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This also covers support for methods optionally taking a lock file.
@@ -176,6 +176,15 @@ def _test(self, path, contents=None): | |||
"encoding": "base64", | |||
"files": {"target": {"contents": encoded}}, | |||
} | |||
|
|||
# Some test methods carry a second file, often a lock file | |||
if additional: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python is EAFP than LBYL therefore a Pythonic way of writing this code block would look like:
try:
read = getattr(additional, "read", None)
additional = additional.read()
encoded = base64.b64encode(additional.encode()).decode()
post_body["files"]["additional"] = {"contents": encoded}
except:
pass
I'm aware of the fact that the code block at the top of this method is LBYL and therefore this one is too, but worth noting IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I refer the consistency vs having two stanzas with different styles. Not against someone refactoring the whole method mind. It requires some additional type hints I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a point there. let's take this one separately as part of a refactor (happy to take it)
@@ -164,7 +164,7 @@ def notification_settings(self): | |||
def invite(self, email: str, admin: bool = False): | |||
raise SnykNotImplementedError # pragma: no cover | |||
|
|||
def _test(self, path, contents=None): | |||
def _test(self, path, contents=None, additional=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we add type hints for this method as well, like so:
def _test(self, path: str, contents: typing.IO = None, additional: typing.IO = None)
using typing.IO will cover both binary(if necessary) and text file-like objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't quite work as is, as the interface accepts file handles or strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying, API looks ambiguous to me. shouldn't the function calling _test
be the one reading the file content and passing that on? I guess this is an inherited design smell.
worth a re-factor, though I'm sure we'll have to consider backwards compatibility here.
for instance why test_pipfile(self, content)
is acting like test_pipfile_content(self, content)
while what I think would be cleaner is:
""" test_pipfile tests a pip file for issue """
def test_pipfile(self, pip_file: typing.TextIO ) -> bool:
with open(pip_file) as f:
self._test(contents=f.read())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some suggestions to make the code more pythonic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on the fence with this one as _test()
is ambiguous and adding parameters that contribute to it make it even more.
worth considering a re-factor of this one ( bet backwards compatibility would be the challenge here)
@@ -164,7 +164,7 @@ def notification_settings(self): | |||
def invite(self, email: str, admin: bool = False): | |||
raise SnykNotImplementedError # pragma: no cover | |||
|
|||
def _test(self, path, contents=None): | |||
def _test(self, path, contents=None, additional=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying, API looks ambiguous to me. shouldn't the function calling _test
be the one reading the file content and passing that on? I guess this is an inherited design smell.
worth a re-factor, though I'm sure we'll have to consider backwards compatibility here.
for instance why test_pipfile(self, content)
is acting like test_pipfile_content(self, content)
while what I think would be cleaner is:
""" test_pipfile tests a pip file for issue """
def test_pipfile(self, pip_file: typing.TextIO ) -> bool:
with open(pip_file) as f:
self._test(contents=f.read())
Added support for more test methods, including Yarn and Composer
This also covers support for methods optionally taking a lock file.